/*
 * Copyright 2008 Karel Klic.
 * This file is part of Oslavanský Bot.
 * 
 * Oslavanský Bot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package categorybot;

import net.sourceforge.jwbf.bots.*;
import net.sourceforge.jwbf.actions.http.*;
import java.net.*;
import java.util.*;
import net.sourceforge.jwbf.contentRep.mw.*;

public class WikiService {

  private MediaWikiBot bot;
  private String from = null;
  private String prefix = null;

  public WikiService(String userName, String password) throws
          MalformedURLException, ActionException {
    bot = new MediaWikiBot("http://cs.wiktionary.org/w/index.php?title=Speciální:Userlogin");
    bot.login(userName, password);
  }

  public void setFrom(String from) {
    this.from = from;
  }

  public void setPrefix(String prefix) {
    this.prefix = prefix;
  }

  public Iterator<String> getIterator() throws ActionException {
    Iterable<String> list = bot.getAllPageTitles(from, prefix, false, true);
    return list.iterator();
  }

  /**
   * 
   * @param name
   *            of article in a mediawiki like "Main Page"
   * @return a content representation of requested article, never null
   * @throws ActionException
   *             on problems with http, cookies and io
   * @throws ProcessException on access problems
   */
  public final ContentAccessable readContent(final String name) 
          throws ActionException, ProcessException {
    return bot.readContent(name);
  }
  
  public void writeContent(ContentAccessable content) 
          throws ActionException, ProcessException {
    bot.writeContent(content);
  }
}
